package com.census.dao.impl;

import com.census.dao.CensusManagerDao;
import com.census.database.DBManager;
import com.census.entity.Census;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * Created by WangKai's Hands.
 * User:WangKai
 * Date:2017/7/1
 * Time:12:26
 * Email: 1786025737@qq.com
 */
public class CensusDao extends DBManager implements CensusManagerDao {

    @Override
    public int InsertCnesus(Census census) throws SQLException {
        String sql = "insert into census (census_num,holder_name,holder_id,family_size,address_id) VALUES(?,?,?,?,?)";
        Object[] obs={census.getCensusNum(),census.getHolderName(),census.getHolderId(),census.getFamilySize(),10001};
        Connection conn = this.openConnection();
        int count = this.update(conn,sql,obs);
        this.closeConnection(conn);
        System.out.println(count);
        System.out.println("54496161");
        return count;
    }

    public static void main(String[] args) throws SQLException {
        Census census = new Census();
        census.setCensusNum(10003);
        census.setHolderName("王菲菲2");
        census.setHolderId("610324199501253344");
        census.setFamilySize(4);
        new CensusDao().InsertCnesus(census);
    }
}
